--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.
--Data Schema For Version 0.0.0.0
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperDelete]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperDelete]
(
	@Original_ShipperID Int
)
AS
SET NOCOUNT OFF;

DELETE FROM 
	[Shippers] 
WHERE 
	[ShipperID] = @Original_ShipperID ;

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperSelectByShipperPks]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperSelectByShipperPks]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE [dbo].[gen_ShipperSelectByShipperPks]
(
	@xml ntext
)
AS

DECLARE @hDoc int
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xml

SELECT
		[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]

FROM 
[Shippers]
WHERE

	[Shippers].[ShipperID] IN (SELECT [ShipperID] 
											FROM OpenXML(@hDoc, '//Shippers', 2) 
											WITH ([ShipperID] char(36) 'ShipperID')) 


exec sp_xml_removeDocument @hDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperSelectByShipperSinglePk]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperSelectByShipperSinglePk]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperSelectByShipperSinglePk]
(
	@ShipperID Int
)
AS

SELECT 
	[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]

FROM
[Shippers]
WHERE 
[Shippers].[ShipperID] = @ShipperID 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperInsert]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[gen_ShipperInsert]
(
	@ShipperID Int = default,
	@Phone NVarChar(24) = default,
	@CompanyName NVarChar(40) = default,
	@created_date datetime,
	@created_by varchar (50),
	@modified_by varchar (50)

)
AS
SET NOCOUNT OFF;

if (@created_date IS NULL)
SET @created_date = GetDate()
IF (@ShipperID < 0) SET @ShipperID = NULL;
if ((@ShipperID IS NULL))
BEGIN

INSERT INTO [Shippers]
(
[CompanyName],
[Phone],
[created_date],
[created_by],
[modified_date],
[modified_by]

)
VALUES
(
	@CompanyName,
	@Phone,
	@created_date,
	@created_by,
	@created_date,
	@modified_by

);

END
ELSE
BEGIN
SET identity_insert [Shippers] on
INSERT INTO [Shippers]
(
[ShipperID],
[CompanyName],
[Phone],
[created_date],
[created_by],
[modified_date],
[modified_by]

)
VALUES
(
	@ShipperID,
	@CompanyName,
	@Phone,
	@created_date,
	@created_by,
	@created_date,
	@modified_by

);
SET identity_insert [Shippers] off
END


SELECT 
	[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]

FROM
[Shippers]
WHERE
	[Shippers].[ShipperID] = SCOPE_IDENTITY();
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperPagingSelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperPagingSelect]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperPagingSelect]
(
	@page int, -- page number selected by the user
	@pageSize int, -- number of items on the page
	@orderByColumn varchar(100), -- name of column to order things by
	@ascending bit, -- order column ascending or descending
	@filter varchar(100) = null, -- filter statement passed in to determine like criteria on order by column
	@count int out -- number of items in the collection
)
AS

SET NOCOUNT ON;


CREATE TABLE #tmpTable
(
[ShipperID] Int
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@pageSize * @page)
IF (@total__ivqatedr <> 0)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[shipperid]
)
SELECT
	[Shippers].[shipperid]
FROM
[Shippers]
WHERE
	(@orderByColumn = 'ShipperID' and (((@filter is null) or ([Shippers].[ShipperID] is null)) or (@filter is not null and [Shippers].[ShipperID] = @filter)))
or
	(@orderByColumn = 'Phone' and (((@filter is null) or ([Shippers].[Phone] is null)) or (@filter is not null and [Shippers].[Phone] LIKE @filter)))
or
	(@orderByColumn = 'CompanyName' and (((@filter is null) or ([Shippers].[CompanyName] is null)) or (@filter is not null and [Shippers].[CompanyName] LIKE @filter)))
ORDER BY
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END

-- set @count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @count = (
SELECT count(*)
FROM
[Shippers]
WHERE
	(@orderByColumn = 'ShipperID' and (((@filter is null) or ([Shippers].[ShipperID] is null)) or (@filter is not null and [Shippers].[ShipperID] = @filter)))
or
	(@orderByColumn = 'Phone' and (((@filter is null) or ([Shippers].[Phone] is null)) or (@filter is not null and [Shippers].[Phone] LIKE @filter)))
or
	(@orderByColumn = 'CompanyName' and (((@filter is null) or ([Shippers].[CompanyName] is null)) or (@filter is not null and [Shippers].[CompanyName] LIKE @filter)))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@pageSize * @page) - @pageSize
IF (@total__ivqatedr <> 0)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
SET ROWCOUNT @pageSize
SELECT
	[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [Shippers] ON #tmpTable.[shipperid] = [SHIPPERS].[shipperid]
ORDER BY
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END

DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperSelectBySearchAnd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperSelectBySearchAnd]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperSelectBySearchAnd]
(
	@ShipperID Int = null, 
	@Phone NVarChar(24) = null, 
	@CompanyName NVarChar(40) = null, 
	@paging_PageIndex int = -1, -- page number selected by the user
	@paging_RecordsperPage int = -1, -- number of items on the page
	@paging_OrderByColumn varchar(100) = '', -- name of column to order things by
	@paging_Ascending bit = 1, -- order column ascending or descending
	@paging_Count int out -- number of items in the collection
)
AS

CREATE TABLE #tmpTable 
(
	[ShipperID] Int
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex)
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[shipperid]
)
SELECT
	[Shippers].[shipperid]
FROM
[Shippers]
WHERE
((@ShipperID is null) OR ([Shippers].[ShipperID] = @ShipperID)) AND
((@Phone is null) OR ([Shippers].[Phone] LIKE @Phone)) AND
((@CompanyName is null) OR ([Shippers].[CompanyName] LIKE @CompanyName))
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END
-- set @paging_Count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @paging_Count = (
SELECT count(*)
FROM
[Shippers]
WHERE
((@ShipperID is null) OR ([Shippers].[ShipperID] = @ShipperID)) AND
((@Phone is null) OR ([Shippers].[Phone] LIKE @Phone)) AND
((@CompanyName is null) OR ([Shippers].[CompanyName] LIKE @CompanyName))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex) - @paging_RecordsperPage
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
IF (@paging_PageIndex <> -1)
BEGIN
SET ROWCOUNT @paging_RecordsperPage
END
SELECT
	[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [Shippers] ON #tmpTable.[shipperid] = [SHIPPERS].[shipperid]
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END
DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperUpdate]
GO


SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperUpdate]
(
	@Phone NVarChar(24),
	@CompanyName NVarChar(40),
	@modified_by varchar (50),
	@modified_date datetime = null,
	@Original_ShipperID Int,
	@Original_time_stamp timestamp

)
AS

IF (@modified_date IS NULL)
SET @modified_date = GetDate();

SET NOCOUNT OFF;
UPDATE 
[Shippers] 
SET
[CompanyName] = @CompanyName,
[Phone] = @Phone,
[modified_by] = @modified_by,
[modified_date] = @modified_date

WHERE
	[Shippers].[ShipperID] = @Original_ShipperID AND
	[Shippers].[time_stamp] = @Original_time_stamp


SELECT
	[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]
FROM 
[Shippers]
WHERE
	[Shippers].[ShipperID] = @Original_ShipperID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperSelectByCreatedDateRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperSelectByCreatedDateRange]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperSelectByCreatedDateRange]
(
	@start_date datetime,
	@end_date datetime
)
AS

SET NOCOUNT ON;

SELECT
		[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]

FROM
[Shippers]
WHERE
((([Shippers].[created_date] IS NULL) AND (@start_date IS NULL)) OR (@start_date <= [Shippers].[created_date])) AND 
((([Shippers].[created_date] IS NULL) AND (@end_date IS NULL)) OR (@end_date >= [Shippers].[created_date]))
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperSelectByModifiedDateRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperSelectByModifiedDateRange]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperSelectByModifiedDateRange]
(
	@start_date datetime,
	@end_date datetime
)
AS

SET NOCOUNT ON;

SELECT
		[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]

FROM
[Shippers]
WHERE
((([Shippers].[modified_date] IS NULL) AND (@start_date IS NULL)) OR (@start_date <= [Shippers].[modified_date])) AND 
((([Shippers].[modified_date] IS NULL) AND (@end_date IS NULL)) OR (@end_date >= [Shippers].[modified_date]))
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperSelectBySearchOr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperSelectBySearchOr]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperSelectBySearchOr]
(
	@ShipperID Int = null, 
	@Phone NVarChar(24) = null, 
	@CompanyName NVarChar(40) = null, 
	@paging_PageIndex int = -1, -- page number selected by the user
	@paging_RecordsperPage int = -1, -- number of items on the page
	@paging_OrderByColumn varchar(100) = '', -- name of column to order things by
	@paging_Ascending bit = 1, -- order column ascending or descending
	@paging_Count int out -- number of items in the collection
)
AS

CREATE TABLE #tmpTable 
(
	[ShipperID] Int
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex)
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[shipperid]
)
SELECT
	[Shippers].[shipperid]
FROM
[Shippers]
WHERE
((@ShipperID is null) OR ([Shippers].[ShipperID] = @ShipperID)) OR
((@Phone is null) OR ([Shippers].[Phone] LIKE @Phone)) OR
((@CompanyName is null) OR ([Shippers].[CompanyName] LIKE @CompanyName))
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END
-- set @paging_Count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @paging_Count = (
SELECT count(*)
FROM
[Shippers]
WHERE
((@ShipperID is null) OR ([Shippers].[ShipperID] = @ShipperID)) OR
((@Phone is null) OR ([Shippers].[Phone] LIKE @Phone)) OR
((@CompanyName is null) OR ([Shippers].[CompanyName] LIKE @CompanyName))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex) - @paging_RecordsperPage
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
IF (@paging_PageIndex <> -1)
BEGIN
SET ROWCOUNT @paging_RecordsperPage
END
SELECT
	[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [Shippers] ON #tmpTable.[shipperid] = [SHIPPERS].[shipperid]
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'ShipperID' THEN [Shippers].[ShipperID] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'Phone' THEN [Shippers].[Phone] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'CompanyName' THEN [Shippers].[CompanyName] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [Shippers].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [Shippers].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [Shippers].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [Shippers].[modified_date] END END
DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_ShipperSelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_ShipperSelect]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_ShipperSelect]
AS

SET NOCOUNT ON;

SELECT
		[Shippers].[shipperid],
	[Shippers].[phone],
	[Shippers].[companyname],
	[Shippers].[created_by],
	[Shippers].[created_date],
	[Shippers].[modified_by],
	[Shippers].[modified_date],
	[Shippers].[time_stamp]

FROM 
[Shippers]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

